use std::sync::mpsc::Sender;

#[derive(Debug, Clone)]
pub enum AppEvent {
    // // 连接相关事件
    // ConnectSuccess { protocol: String, addr: String },
    // ConnectFailed { reason: String },
    // Disconnected,

    // // 数据收发事件
    // DataReceived { data: Vec<u8>, timestamp: String },
    // DataSent { data: Vec<u8>, length: usize },



    // // 界面控制事件
    // ClearRecvArea,
    // SaveRecvData,
    // SendModeChanged { hex: bool },
    // RecvModeChanged { hex: bool },

    // left_panel
    EventConnected { e_is_connected : bool },
    EventHexSend {is_hex: bool},
    EventButtonTimer,
    EventClearRecv,
    EventSaveRecv,
    EventHexRecvShow { is_hex: bool },
    EventProtocolChanged { protocol: u32 },
}

pub struct EventSender {
    tx: Sender<AppEvent>,
}

impl EventSender {
    pub fn new(tx: Sender<AppEvent>) -> Self {
        Self { tx }
    }

    pub fn clone(&self) -> Self {
        Self { tx: self.tx.clone() }
    }

    pub fn send(&self, event: AppEvent) {
        self.tx.send(event).unwrap();
    }
}
